/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.matheval;
import simhya.matheval.operator.OperatorDefinition;


/**
 *
 * @author Luca
 */
public abstract class OperatorNode extends ExpressionNode {
    protected OperatorDefinition operator;


    public OperatorNode(OperatorDefinition op, int numberOfChildren) {
        super(numberOfChildren);
        this.operator = op;
    }

    String getExpressionString(boolean fullNumberRepresentation) {
        String s = "";
        switch(numberOfChildren) {
            case 1:
                s += operator.getStringRepresentation() + children[0].getExpressionString(false);
                break;
            case 2:
                s += "(" + children[0].getExpressionString(false) + " ";
                s += operator.getStringRepresentation() + " ";
                s += children[1].getExpressionString(false) + ")";
                break;
            default:
                throw new EvalException("Operator node has wrong number of children (" + numberOfChildren + ")");
        }    
        return s;
    }

    @Override
    public boolean isLogicalExpression() {
        String op  = operator.getStringRepresentation();
        if (op.equals("&&") || op.equals("||") || op.equals("!") ||
                op.equals("==") || op.equals("!=") || op.equals("<") ||
                op.equals(">") || op.equals("<=") || op.equals(">=") )
            return true;
        else return false;
    }



    abstract void computeValue();
    abstract void computeValue(SymbolArray varReference);
    abstract void computeValue(int evaluationCode);
    abstract void computeValue(SymbolArray varReference, int evaluationCode);

}
